/*
 * @(#)MaintCalendarRecordForm.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
     * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.calendar.web;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.dcivision.calendar.bean.CalendarRecord;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;


/**
 MaintCalendarRecordForm.java
 This class is the for web form purpose.
 @author      Robert Jin
 @company     DCIVision Limited
 @creation date   18/12/2003
 @version     $Revision: 1.26 $
 */
public class MaintCalendarRecordForm
    extends com.dcivision.alert.web.MaintUpdateAlertForm {
    private String ownerID = null;
    private String sourceID = null;
    private String parentID = null;
    private String companyID = null;
    private String updateAlertID = null;
    private String sourceType = null;
    private String activityType = null;
    private String eventType = null;
    private String title = null;
    private String detail = null;
    private String purpose = null;
    private String datetime = null;
    private String endtime = null;
    private String isWholeDay = null;
    private String priority = null;
    private String status = null;
    private String venue = null;
    private String shareType = null;
    private String alertType = null;
    private String reminderAmount = null;
    private String reminderType = null;
    private String report = null;
    private String recordStatus = null;
    private String isRecurrence = null;
    private String recipientType = null;
    private String systemReminder = null;
    private String emailReminder = null;

    //    private String datetime = null;
    // These 3 fields add for operation of 'datetime'
    private String startDate = null;
    private String startHour = null;
    private String startMinute = null;

    //    private String endtime = null;
    // These 3 fields add for operation of 'endtime'
    private String endDate = null;
    private String endHour = null;
    private String endMinute = null;
    private String[] userIDsToShare = null;
    private String[] groupIDsToShare = null;
    private String[] roleIDsToShare = null;
    private String[] userIDsForMeeting = null;

    //for update alert
    private String[] notifyWay = new String[0];
    private String needReply = null;

    //for recurring record
    private String recurStartDate = null;
    private String recurEndDate = null;
    private String repeatTimes = null;
    private String recurType = null;
    private String repeatOn = null;
    private String repeatType = null;
    private String repeatTypeDay = null;
    private String occurType = null;
    private String occurWeekDay = null;
    private String occurMonth = null;

    //for invite
    private String[] userRecords = new String[0];
    private String[] userGroups = new String[0];
    private String[] userRoles = new String[0];

    //for submeeting
    private int subMeetingNum = 0;
    private String refreshIntervalDays = null;

    /*
      private String[] subMeetingStartTime = new String[0];
      private String[] subMeetingEndTime = new String[0];
      private String[] subMeetingIsFullDay = new String[0];
    */
    public String[] getUserRecords() {
        return this.userRecords;
    }

    public void setUserRecords(String[] userRecords) {
        this.userRecords = userRecords;
    }

    public String[] getUserGroups() {
        return this.userGroups;
    }

    public void setUserGroups(String[] userGroups) {
        this.userGroups = userGroups;
    }

    public String[] getUserRoles() {
        return this.userRoles;
    }

    public void setUserRoles(String[] userRoles) {
        this.userRoles = userRoles;
    }

    public String getOwnerID() {
        return (this.ownerID);
    }

    public void setOwnerID(String ownerID) {
        this.ownerID = ownerID;
    }

    public String getSourceID() {
        return (this.sourceID);
    }

    public void setSourceID(String sourceID) {
        this.sourceID = sourceID;
    }

    public String getParentID() {
        return (this.parentID);
    }

    public void setParentID(String parentID) {
        this.parentID = parentID;
    }

    public String getCompanyID() {
        return (this.companyID);
    }

    public void setCompanyID(String companyID) {
        this.companyID = companyID;
    }

    public String getUpdateAlertID() {
        return (this.updateAlertID);
    }

    public void setUpdateAlertID(String updateAlertID) {
        this.updateAlertID = updateAlertID;
    }

    public String getSourceType() {
        return (this.sourceType);
    }

    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }

    public String getActivityType() {
        return (this.activityType);
    }

    public void setActivityType(String activityType) {
        this.activityType = activityType;
    }

    public String getEventType() {
        return (this.eventType);
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public String getTitle() {
        return (this.title);
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDetail() {
        return (this.detail);
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getPurpose() {
        return (this.purpose);
    }

    public void setPurpose(String purpose) {
        this.purpose = purpose;
    }

    public String getIsWholeDay() {
        return (this.isWholeDay);
    }

    public void setIsWholeDay(String isWholeDay) {
        this.isWholeDay = isWholeDay;
    }

    public String getIsRecurrence() {
        return (this.isRecurrence);
    }

    public void setIsRecurrence(String isRecurrence) {
        this.isRecurrence = isRecurrence;
    }

    public String getPriority() {
        return (this.priority);
    }

    public void setPriority(String priority) {
        this.priority = priority;
    }

    public String getStatus() {
        return (this.status);
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getVenue() {
        return (this.venue);
    }

    public void setVenue(String venue) {
        this.venue = venue;
    }

    public String getShareType() {
        return (this.shareType);
    }

    public void setShareType(String shareType) {
        this.shareType = shareType;
    }

    public String getAlertType() {
        return (this.alertType);
    }

    public void setAlertType(String alertType) {
        this.alertType = alertType;
    }

    public String getReminderAmount() {
        return (this.reminderAmount);
    }

    public void setReminderAmount(String reminderAmount) {
        this.reminderAmount = reminderAmount;
    }

    public String getReminderType() {
        return (this.reminderType);
    }

    public void setReminderType(String reminderType) {
        this.reminderType = reminderType;
    }

    public String getReport() {
        return (this.report);
    }

    public void setReport(String report) {
        this.report = report;
    }

    public String getRecordStatus() {
        return (this.recordStatus);
    }

    public void setRecordStatus(String recordStatus) {
        this.recordStatus = recordStatus;
    }

    public Timestamp getDatetime() {
        StringBuffer fullTime = new StringBuffer();
        fullTime.append(startDate).append(" ")
                .append((startHour == null) ? "0" : startHour).append(":")
                .append((startMinute == null) ? "0" : startMinute).append(":")
                .append(0);

        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                    SystemParameterConstant.DB_DATETIME_FORMAT),
                new Locale(SystemParameterFactory.getSystemParameter(
                        SystemParameterConstant.LOCALE)));
        Date tempDate = null;

        try {
            tempDate = formatter.parse(fullTime.toString());
        } catch (java.text.ParseException pe) {
            return null;
        }

        return new Timestamp(tempDate.getTime());
    }

    public void setDatetime(Timestamp datetime) {
        if (datetime != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(datetime.getTime());

            StringBuffer dateString = new StringBuffer();
            dateString.append(calendar.get(Calendar.MONTH) + 1).append("/");
            dateString.append(calendar.get(Calendar.DATE)).append("/");
            dateString.append(calendar.get(Calendar.YEAR));

            try {
                SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy",
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                java.util.Date date = formatter.parse(dateString.toString());
                SimpleDateFormat formatter1 = new SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT).substring(0,10),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                this.startDate = formatter1.format(date);
            } catch (ParseException e) {
                this.startDate = null;
            }

            this.startHour = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
            this.startMinute = String.valueOf(calendar.get(Calendar.MINUTE));
        } else {
            this.startDate = null;
            this.startHour = null;
            this.startMinute = null;
        }
    }

    public Timestamp getEndtime() {
        StringBuffer fullTime = new StringBuffer();
        fullTime.append(endDate).append(" ")
                .append((endHour == null) ? "0" : endHour).append(":")
                .append((endMinute == null) ? "0" : endMinute).append(":")
                .append(0);

        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                    SystemParameterConstant.DB_DATETIME_FORMAT),
                new Locale(SystemParameterFactory.getSystemParameter(
                        SystemParameterConstant.LOCALE)));
        Date tempDate = null;

        try {
            tempDate = formatter.parse(fullTime.toString());
        } catch (java.text.ParseException pe) {
            return null;
        }

        return new Timestamp(tempDate.getTime());
    }

    public void setEndtime(Timestamp datetime) {
        if (datetime != null) { // Use 'datetime' here as it should be in the same day.

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(datetime.getTime());

            StringBuffer dateString = new StringBuffer();
            dateString.append(calendar.get(Calendar.MONTH) + 1).append("/");
            dateString.append(calendar.get(Calendar.DATE)).append("/");
            dateString.append(calendar.get(Calendar.YEAR));

            try {
                SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy",
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                java.util.Date date = formatter.parse(dateString.toString());
                SimpleDateFormat formatter1 = new SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT).substring(0,10),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                this.endDate = formatter1.format(date);
            } catch (ParseException e) {
                this.endDate = null;
            }

            this.endHour = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
            this.endMinute = String.valueOf(calendar.get(Calendar.MINUTE));
        } else {
            this.endDate = null;
            this.endHour = null;
            this.endMinute = null;
        }
    }

    public void setStartDate(String startDate) {
        try {
            if (startDate != null) {
                //        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
                java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT).substring(0,10));
                java.util.Date date = formatter.parse(startDate);
                java.text.SimpleDateFormat formatter1 = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT).substring(0,10),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                this.startDate = formatter1.format(date);
            } else {
                this.startDate = startDate;
            }
        } catch (java.text.ParseException e) {
        }
    }

    public String getStartDate() {
        return startDate;
    }

    public void setStartHour(String startHour) {
        this.startHour = startHour;
    }

    public String getStartHour() {
        return startHour;
    }

    public void setStartMinute(String startMinute) {
        this.startMinute = startMinute;
    }

    public String getStartMinute() {
        return startMinute;
    }

    public void setEndHour(String endHour) {
        this.endHour = endHour;
    }

    public void setEndDate(String endDate) {
        try {
            if (endDate != null) {
                java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT).substring(0,10));
                java.util.Date date = formatter.parse(endDate);
                java.text.SimpleDateFormat formatter1 = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT).substring(0,10),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                this.endDate = formatter1.format(date);
            } else {
                this.endDate = endDate;
            }
        } catch (java.text.ParseException e) {
        }
    }

    public String getEndDate() {
        return endDate;
    }

    public String getEndHour() {
        return endHour;
    }

    public void setEndMinute(String endMinute) {
        this.endMinute = endMinute;
    }

    public String getEndMinute() {
        return endMinute;
    }

    public void setUserIDsToShare(String[] userIDsToShare) {
        this.userIDsToShare = userIDsToShare;
    }

    public String[] getUserIDsToShare() {
        return (this.userIDsToShare);
    }

    public void setGroupIDsToShare(String[] groupIDsToShare) {
        this.groupIDsToShare = groupIDsToShare;
    }

    public String[] getGroupIDsToShare() {
        return (this.groupIDsToShare);
    }

    public void setRoleIDsToShare(String[] roleIDsToShare) {
        this.roleIDsToShare = roleIDsToShare;
    }

    public String[] getRoleIDsToShare() {
        return (this.roleIDsToShare);
    }

    public void setUserIDsForMeeting(String[] userIDsForMeeting) {
        this.userIDsForMeeting = userIDsForMeeting;
    }

    public String[] getUserIDsForMeeting() {
        return (this.userIDsForMeeting);
    }

    public void setEmailReminder(String emailReminder) {
        this.emailReminder = emailReminder;
    }

    public String getEmailReminder() {
        return this.emailReminder;
    }

    public void setSystemReminder(String systemReminder) {
        this.systemReminder = systemReminder;
    }

    public String getSystemReminder() {
        return this.systemReminder;
    }

    public String[] getNotifyWay() {
        return (this.notifyWay);
    }

    public void setNotifyWay(String[] notifyWay) {
        this.notifyWay = notifyWay;
    }

    public void setNeedReply(String needReply) {
        this.needReply = needReply;
    }

    public String getNeedReply() {
        return this.needReply;
    }

    public String getRecurStartDate() {
        return (this.recurStartDate);
    }

    public void setRecurStartDate(String recurStartDate) {
        try {
            if (recurStartDate != null) {
                java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                java.util.Date date = formatter.parse(recurStartDate);
                java.text.SimpleDateFormat formatter1 = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                this.recurStartDate = formatter1.format(date);
            } else {
                this.recurStartDate = recurStartDate;
            }
        } catch (java.text.ParseException e) {
        }
    }

    public String getRecurEndDate() {
        return (this.recurEndDate);
    }

    public void setRecurEndDate(String recurEndDate) {
        try {
            if (recurEndDate != null) {
                java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                java.util.Date date = formatter.parse(recurEndDate);
                java.text.SimpleDateFormat formatter1 = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                            SystemParameterConstant.DB_DATETIME_FORMAT),
                        new Locale(SystemParameterFactory.getSystemParameter(
                                SystemParameterConstant.LOCALE)));
                this.recurEndDate = formatter1.format(date);
            } else {
                this.recurEndDate = recurEndDate;
            }
        } catch (java.text.ParseException e) {
        }
    }

    public String getRepeatTimes() {
        return (this.repeatTimes);
    }

    public void setRepeatTimes(String repeatTimes) {
        this.repeatTimes = repeatTimes;
    }

    public String getRecurType() {
        return (this.recurType);
    }

    public void setRecurType(String recurType) {
        this.recurType = recurType;
    }

    public String getRepeatOn() {
        return (this.repeatOn);
    }

    public void setRepeatOn(String repeatOn) {
        this.repeatOn = repeatOn;
    }

    public String getRepeatType() {
        return (this.repeatType);
    }

    public void setRepeatType(String repeatType) {
        this.repeatType = repeatType;
    }

    public String getRepeatTypeDay() {
        return (this.repeatTypeDay);
    }

    public void setRepeatTypeDay(String repeatTypeDay) {
        this.repeatTypeDay = repeatTypeDay;
    }

    public String getOccurType() {
        return (this.occurType);
    }

    public void setOccurType(String occurType) {
        this.occurType = occurType;
    }

    public String getOccurWeekDay() {
        return (this.occurWeekDay);
    }

    public void setOccurWeekDay(String occurWeekDay) {
        this.occurWeekDay = occurWeekDay;
    }

    public String getOccurMonth() {
        return (this.occurMonth);
    }

    public void setOccurMonth(String occurMonth) {
        this.occurMonth = occurMonth;
    }

    public String getRecipientType() {
        return (this.recipientType);
    }

    public void setRecipientType(String recipientType) {
        this.recipientType = recipientType;
    }

    public int getSubMeetingNum() {
        return (this.subMeetingNum);
    }

    public void setRefreshIntervalDays(String refreshIntervalDays) {
        this.refreshIntervalDays = refreshIntervalDays;
    }
    
    public String getRefreshIntervalDays() {
      return (this.refreshIntervalDays);
  }

  public void setSubMeetingNum(int subMeetingNum) {
      this.subMeetingNum = subMeetingNum;
  }

    public ActionErrors validate(ActionMapping mapping,
        HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        //Update By Jim.Zhou			2006/06/15			Bug	#5723
        if (!Utility.isEmpty(this.getIsWholeDay()) && "Y".equals(this.getIsWholeDay())){
          if ((!GlobalConstant.NAV_MODE_REFRESH.equals(request.getParameter("opMode"))) 
                  &&(this.getDatetime() != null) && (this.getEndtime() != null) &&
                  (this.getDatetime().after(this.getEndtime()))) {
            errors.add("startDate", new ActionError("calendar.error.startdate"));
          }
	      } else {
          if ((!GlobalConstant.NAV_MODE_REFRESH.equals(request.getParameter("opMode"))) 
                  &&(this.getDatetime() != null) && (this.getEndtime() != null) &&
                  (this.getDatetime().after(this.getEndtime())|| this.getDatetime().equals(this.getEndtime()))) {
            errors.add("startDate", new ActionError("calendar.error.startdate"));
          }
	      }
        //Update End

        /* if((this.getNotifyWay()!=null) && (this.getRecipientType()!=null)){
           errors.add("NotifyWay",new ActionError("NotifyWay must required!"));
         }*/
        
        String[] userRecords = null;
        String[] userRoles = null;
        String[] userGroups = null;
        userRecords = request.getParameterValues("userRecords");
        userRoles = request.getParameterValues("userRoles");
        userGroups = request.getParameterValues("userGroups");
        this.setUserList(userRecords);
        this.setRoleList(userRoles);
        this.setGroupList(userGroups);       
        
        
        return errors;
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
        this.setID(null);
        this.setOwnerID(null);
        this.setSourceID(null);
        this.setParentID(null);
        this.setCompanyID(null);
        this.setUpdateAlertID(null);
        this.setSourceType(null);
        this.setActivityType(null);
        this.setEventType(null);
        this.setTitle(null);
        this.setDetail(null);
        this.setPurpose(null);
        this.setDatetime(null);
        this.setEndtime(null);
        this.setIsWholeDay(null);
        this.setPriority(GlobalConstant.PRIORITY_MEDIUM);
        this.setStatus(null);
        this.setVenue(null);
        this.setShareType("U");
        this.setAlertType(null);
        this.setReminderAmount(null);
        this.setReminderType(null);
        this.setReport(null);
        this.setRecordStatus(null);
        this.setCreatorID(null);
        this.setCreateDate(null);
        this.setUpdaterID(null);
        this.setUpdateDate(null);
        this.setNotifyWay(new String[0]);
        this.setNeedReply(null);
        this.setIsRecurrence(null);
        this.setStartDate(null);
        this.setEndDate(null);
        this.setRepeatTimes(null);
        this.setRecurType(null);
        this.setRepeatOn(null);
        this.setRepeatType(null);
        this.setRepeatTypeDay(null);
        this.setOccurType(null);
        this.setOccurWeekDay(null);
        this.setOccurMonth(null);
        this.setSubMeetingNum(0);
    }

    public AbstractBaseObject getFormData() throws ApplicationException {
        CalendarRecord tmpCalendarRecord = new CalendarRecord();
        tmpCalendarRecord.setID(TextUtility.parseIntegerObj(this.getID()));
        tmpCalendarRecord.setOwnerID(TextUtility.parseIntegerObj(
                this.getOwnerID()));
        tmpCalendarRecord.setSourceID(TextUtility.parseIntegerObj(
                this.getSourceID()));
        tmpCalendarRecord.setParentID(TextUtility.parseIntegerObj(
                this.getParentID()));
        tmpCalendarRecord.setCompanyID(TextUtility.parseIntegerObj(
                this.getCompanyID()));
        tmpCalendarRecord.setUpdateAlertID(TextUtility.parseIntegerObj(
                this.getUpdateAlertID()));
        tmpCalendarRecord.setSourceType(this.getSourceType());
        tmpCalendarRecord.setActivityType(this.getActivityType());
        tmpCalendarRecord.setEventType(this.getEventType());
        tmpCalendarRecord.setTitle(this.getTitle());
        tmpCalendarRecord.setDetail(this.getDetail());
        tmpCalendarRecord.setPurpose(this.getPurpose());
        tmpCalendarRecord.setDatetime(this.getDatetime());
        tmpCalendarRecord.setEndtime(this.getEndtime());
        tmpCalendarRecord.setIsWholeDay(this.getIsWholeDay());
        tmpCalendarRecord.setPriority(this.getPriority());
        tmpCalendarRecord.setStatus(this.getStatus());
        tmpCalendarRecord.setVenue(this.getVenue());
        tmpCalendarRecord.setShareType(this.getShareType());
        tmpCalendarRecord.setAlertType(TextUtility.parseIntegerObj(
                this.getAlertType()));
        tmpCalendarRecord.setReminderAmount(TextUtility.parseIntegerObj(
                this.getReminderAmount()));
        tmpCalendarRecord.setReminderType(this.getReminderType());
        tmpCalendarRecord.setReport(this.getReport());
        tmpCalendarRecord.setRecordStatus(this.getRecordStatus());
        tmpCalendarRecord.setCreatorID(TextUtility.parseIntegerObj(
                this.getCreatorID()));
        tmpCalendarRecord.setCreateDate(TextUtility.parseTimestamp(
                this.getCreateDate()));
        tmpCalendarRecord.setUpdaterID(TextUtility.parseIntegerObj(
                this.getUpdaterID()));
        tmpCalendarRecord.setUpdateDate(TextUtility.parseTimestamp(
                this.getUpdateDate()));

        if (notifyWay != null) {
            StringBuffer sb = new StringBuffer();

            for (int i = 0; i < notifyWay.length; i++) {
                sb.append(notifyWay[i]).append(",");
            }

            tmpCalendarRecord.setNotifyWay(sb.toString());
        } else {
            tmpCalendarRecord.setNotifyWay(null);
        }

        tmpCalendarRecord.setIsRecurrence(this.getIsRecurrence());
        tmpCalendarRecord.setRecurStartDate(formateStringToTimestamp(
                this.getRecurStartDate()));
        tmpCalendarRecord.setRecurEndDate(formateStringToTimestamp(
                this.getRecurEndDate()));
        tmpCalendarRecord.setRepeatTimes(TextUtility.parseIntegerObj(
                this.getRepeatTimes()));
        tmpCalendarRecord.setRecurType(this.getRecurType());
        tmpCalendarRecord.setRepeatOn(TextUtility.parseIntegerObj(
                this.getRepeatOn()));
        tmpCalendarRecord.setRepeatType(this.getRepeatType());
        tmpCalendarRecord.setRepeatTypeDay(this.getRepeatTypeDay());
        tmpCalendarRecord.setOccurType(TextUtility.parseIntegerObj(
                this.getOccurType()));
        tmpCalendarRecord.setOccurWeekDay(TextUtility.parseIntegerObj(
                this.getOccurWeekDay()));
        tmpCalendarRecord.setOccurMonth(TextUtility.parseIntegerObj(
                this.getOccurMonth()));

        //tmpCalendarRecord.setNeedReply(this.needReply);
        tmpCalendarRecord.setSubMeetingNum(this.getSubMeetingNum());
        tmpCalendarRecord.setAlertSubject(this.getAlertSubject());
        return tmpCalendarRecord;
    }

    public void setFormData(AbstractBaseObject baseObj)
        throws ApplicationException {
        CalendarRecord tmpCalendarRecord = (CalendarRecord) baseObj;
        this.setID(TextUtility.formatIntegerObj(tmpCalendarRecord.getID()));
        this.setOwnerID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getOwnerID()));
        this.setSourceID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getSourceID()));
        this.setParentID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getParentID()));
        this.setCompanyID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getCompanyID()));
        this.setUpdateAlertID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getUpdateAlertID()));
        this.setSourceType(tmpCalendarRecord.getSourceType());
        this.setActivityType(tmpCalendarRecord.getActivityType());
        this.setEventType(tmpCalendarRecord.getEventType());
        this.setTitle(tmpCalendarRecord.getTitle());
        this.setDetail(tmpCalendarRecord.getDetail());
        this.setPurpose(tmpCalendarRecord.getPurpose());
        this.setDatetime(tmpCalendarRecord.getDatetime());
        this.setEndtime(tmpCalendarRecord.getEndtime());
        this.setIsWholeDay(tmpCalendarRecord.getIsWholeDay());
        this.setPriority(tmpCalendarRecord.getPriority());
        this.setStatus(tmpCalendarRecord.getStatus());
        this.setVenue(tmpCalendarRecord.getVenue());
        this.setShareType(tmpCalendarRecord.getShareType());
        this.setAlertType(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getAlertType()));
        this.setReminderAmount(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getReminderAmount()));
        this.setReminderType(tmpCalendarRecord.getReminderType());
        this.setReport(tmpCalendarRecord.getReport());
        this.setRecordStatus(tmpCalendarRecord.getRecordStatus());
        this.setCreatorID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getCreatorID()));
        this.setCreateDate(TextUtility.formatTimestamp(
                tmpCalendarRecord.getCreateDate()));
        this.setUpdaterID(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getUpdaterID()));
        this.setUpdateDate(TextUtility.formatTimestamp(
                tmpCalendarRecord.getUpdateDate()));

     
        if (tmpCalendarRecord.getNotifyWay() != null) {
            StringTokenizer sToken = new StringTokenizer(tmpCalendarRecord.getNotifyWay(),
                    ",");
            String[] notifyWayArray = new String[sToken.countTokens()];

            for (int i = 0; sToken.hasMoreElements(); i++) {
                notifyWayArray[i] = (String) sToken.nextElement();
            }

            this.setNotifyWay(notifyWayArray);
        } else {
            this.setNotifyWay(null);
        }

        this.setIsRecurrence(tmpCalendarRecord.getIsRecurrence());

        // java.util.Date date = formatter1.parse(recurEndDate);
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(
                    SystemParameterConstant.DB_DATETIME_FORMAT),
                new Locale(SystemParameterFactory.getSystemParameter(
                        SystemParameterConstant.LOCALE)));
        String sRecurStartDate = null;
        String sRecurEndDate = null;

        if (tmpCalendarRecord.getRecurStartDate() != null) {
            sRecurStartDate = formatter.format(tmpCalendarRecord.getRecurStartDate());
        }

        if (tmpCalendarRecord.getRecurEndDate() != null) {
            sRecurEndDate = formatter.format(tmpCalendarRecord.getRecurEndDate());
        }

        this.setRecurStartDate(sRecurStartDate);
        this.setRecurEndDate(sRecurEndDate);

        this.setRepeatTimes(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getRepeatTimes()));
        this.setRecurType(tmpCalendarRecord.getRecurType());
        this.setIsRecurrence(tmpCalendarRecord.getIsRecurrence());
        this.setRepeatOn(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getRepeatOn()));
        this.setRepeatType(tmpCalendarRecord.getRepeatType());
        this.setRepeatTypeDay(tmpCalendarRecord.getRepeatTypeDay());
        this.setOccurType(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getOccurType()));
        this.setOccurWeekDay(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getOccurWeekDay()));
        this.setOccurMonth(TextUtility.formatIntegerObj(
                tmpCalendarRecord.getOccurMonth()));

        //this.setNeedReply(tmpCalendarRecord.getNeedReply());
        this.setRecordStatus(tmpCalendarRecord.getRecordStatus());
        this.setSubMeetingNum(tmpCalendarRecord.getSubMeetingNum());
        this.setAlertSubject(tmpCalendarRecord.getAlertSubject());
    }
    
    public Timestamp formateStringToTimestamp(String inputTimeString){
        java.util.Date selectDate = null;
        java.text.SimpleDateFormat formatter = null;
//        inputTimeString = "2004/06/23 10:05:05";
        if (!Utility.isEmpty(inputTimeString)){
            try{
            formatter = new java.text.SimpleDateFormat(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT), new Locale(SystemParameterFactory.getSystemParameter(SystemParameterConstant.LOCALE)));
            selectDate = formatter.parse(inputTimeString);
            }catch(java.text.ParseException e){                
            }
        }else{
          return null;
        }
        return new Timestamp(selectDate.getTime());
    }    
}
